<?php

namespace App\Http\Controllers\YApi;

// use Illuminate\Http\Request;
use Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Session;
use Redirect;
use Illuminate\Pagination\LengthAwarePaginator;

use App\Models\Book;
use App\Models\Shudan;
use App\Models\UsersReg;

class ShudaninfoController extends Controller
{

  public function shudaninfo($id)
    {
        $shudans = Shudan::find($id);       

        //记录书单浏览次数
        $shudans->click_count = $shudans->click_count + 1;
        $shudans->save();        

        // 用户信息
        $shudans['users'] = UsersReg::where('uid', $shudans->uid)->first();        

        $shudanlist = $shudans->shudanlist;
        $arr = explode(',', $shudanlist); 
        //得到书单对应的书籍信息
        for($i=0; $i < count($arr); $i++){
            $books[$i] = Book::find($arr[$i]);            
        }

        // $shudans['books'] = $books;
        $shudans['geshu'] = count($books);

        return $shudans;
      
    }
    
}